Technology Without An Interesting Name (TWAIN) is an international standard followed by all manufacturers of scanners, digital cameras and other devices; it provides unified regulations between software developers and hardware equipment manufacturers, and effectively avoids the problem of incompatibility between the system and the equipment; once satisfying the TWAIN requirements, an application module can obtain a static image from a peripheral device which satisfies the TWAIN; therefore, the TWAIN is widely applied in the field of scanners.
In order to implement communication between the application module and an image acquisition device (such as a scanner), the TWAIN provides a standard software protocol and a programming interface. There are three core elements (named as elements for short) in the architecture of the TWAIN: 1) an application software: an application module which must satisfy the TWAIN, this software is generally an image processing software; 2) a Data Source (DS) software, which is used for controlling the image acquisition device, is written by the equipment developer, and follows the TWAIN requirements; 3) a data source management software: managing the communication between the application module and the DS; the relationship among the elements are shown in FIG. 1, the TWAIN 10 includes an application software 12, a Data Source Manager (DSM) software 14, a DS software 16 and an image input device 18, wherein, the application software 12 is named as an application module for short, including various application software, such as the image application software; the DSM software 14 is a DSM, named as a source manager for short; the DS software 16, named as DS or source for short, including various DSs, such as the scanner DS. From FIG. 1, it can be seen that the application software 12 cannot directly implement communication with the DS software 16; according to the TWAIN requirements, as shown in FIG. 2, the communication among the elements must be implemented via two functions, namely, DSM_Entry( ) function and DS_Entry( ) function, wherein, DSM refers to the data source manager, DS refers to the data source; the communication between the application module and the DS must be implemented via the DSM, thus realizing the data request, capability setting and the like; but the only entry between the application module and the DSM is the DSM_Entry( ) function, the only entry between the DSM and the DS is the DS_Entry( ); the communication among the elements can be implemented via the DSM_Entry( ) function and DS_Entry( ) function; each communication operation is initiated by the application module or the DSM, and is implemented via triples which are composed of three different parameters; the three composition parameters of the triples are respectively a Data Group (DG_xxxx), a Data Argument Type (DAT_xxxx) and a Message ID (MSG_xxxx); each of the triples uniquely determines one specific operation. Wherein, the operations are divided into two categories via the DG, which are the control operation and the image operation; the control operation is to control the TWAIN session, and is implemented by the Control Data Group (DG_CONTROL); the image operation is relative to the image data, and is implemented by an Image Data Group (DG_IMAGE).
In order to acquire the data, the application module, the DSM and the DS must implement communication to each other, and the process of acquiring the data must be implemented according to a certain sequence. The TWAIN defines seven states of the TWAIN session to guarantee the implementation according to a correct sequence, which can refer to the state transition diagram shown in FIG. 3. A session not only can be a process that the application module is connected to the DS via the DSM, but also can be a process that the application module is connected to the DSM. In a certain time point of the session, the DSM and the DS respectively have different states, a certain request sent from the application module or the DS may cause state transition; the state transition can be forward or backward. Most of the state transitions are single-state transitions, and also can be multi-state transitions.
As shown in FIG. 3, the brief descriptions of the seven states are as follows: state 1, the source manager is not loaded; state 2, the source manager has been loaded; state 3, the source manager has been opened; state 4, the source has been opened, and is capable of implementing capability query and capability setting, such as the capability setting of resolutions, image types, scanning areas and the like; state 5, displaying the user interface; state 6, the transmission is ready; state 7, implementing image transmission. It should note that, the states 1, 2, 3 are occupied by the DSM, the states 4, 5, 6, 7 are occupied by the DS. If one DS is closed, namely, the user interface of an image input device in the application module is closed, the DS corresponding to the image input device has no state.
The states of the DSM and the DS are changed according to the following sequences during the process of acquiring the data. First, after loading the source manager, the DSM enters the state 2 from the state 1; after the DSM enters the state 2, the DSM enters the state 3 from the state 2 after opening the source manager; via opening the source, the DS enters the state 4; and the DS enters the state 5 from the state 4 by enabling the source; the DS enters the state 6 from the state 5 by notifying the application module that the transfer is ready; by requesting the image transmission via the application module, the DS enters the state 7 from the state 6, and transmits the image to the application module. When implementing data transmission, the DS occupies the state 7; when waiting for the scanning data of the scanning device during the data transmission process, the DS occupies the state 6; when the application module cancels the image transmission during the data transmission process, the DS moves from the state 7 to the state 5; when the image transmission ends, the DS moves from the state 6 to the state 5.
Only a determined operation can be implemented in a given state, furthermore, any given operation only can be implemented in the given state. For example, the capability setting only can be implemented in the state 4, the transmission of the scanning image only can be implemented in the state 7. When the DS is the scanner, the setting of capability relative to the scanner (named as the scanning capability for short) is implemented in the state 4, for example, setting the image types, resolutions, image size and the like; when the DS is the composite scanning device (such as a scanning and printing integrated machine), the setting of scanning capability and other capabilities can be implemented in the state 4, for example, defining the print content via the printing capability setting, no matter how the processing result of the scanning image is, the composite scanning device can print the print content. However, in the actual application of the composite scanning device, the printing capability setting needs to be implemented after processing the scanning image, so as to determine whether implementing printing, and to determine the print content, the print position and the like according to the image processing result; thus, the printing capability setting cannot be implemented in advance, and only can be implemented after processing the scanning image. However, according to the TWAIN requirements, the capability setting only can be implemented in the case that the DS returns to the state 4 from the state 7 of the transmission image after the application module processes the scanning image, such operation may cause this scanning operation to end; the user must implement the interface operation again to implement the printing capability setting, which causes low working efficiency and inconvenient use.